<template>
  <div class="front serve">
    <div class="header-box">
      <Header :searchContent = this.$route.query.name$lk></Header>
    </div>

    <div class="goods">
      <!-- <div class="mianbao">
        <span class="btn hover" @click="$router.push('/front-home')">首页</span>
      </div>-->

      <div class="sort">
        <ul>
          <li :class="defaultColor?'active':''" @click="changeSort()">综合排序</li>
          <li @click="changeSort(1,listQuery.shopDealNum$sort)">
            成交量
            <span>
              <i size="16px" class="el-icon-caret-top" :class="listQuery.shopDealNum$sort=='asc'?'active':''"></i>
              <i size="16px" class="el-icon-caret-bottom" :class="listQuery.shopDealNum$sort=='desc'?'active':''"></i>
            </span>
          </li>
          <li @click="changeSort(2,listQuery.shopViewNum$sort)">
            浏览量
            <span>
              <i class="el-icon-caret-top" :class="listQuery.shopViewNum$sort=='asc'?'active':''"></i>
              <i class="el-icon-caret-bottom" :class="listQuery.shopViewNum$sort=='desc'?'active':''"></i>
            </span>
          </li>
          <li @click="changeSort(3,listQuery.shopCollectNum$sort)">
            收藏量
            <span>
              <i class="el-icon-caret-top" :class="listQuery.shopCollectNum$sort=='asc'?'active':''"></i>
              <i class="el-icon-caret-bottom" :class="listQuery.shopCollectNum$sort=='desc'?'active':''"></i>
            </span>
          </li>
        </ul>
      </div>
      <div class="productList">
        <div class="item2-list" v-for="(item,index) in list" :key="index">
          <div class="item2-top">
            <div class="left">
              <div class="avator">
                <img :src="item.shopImage ? item.shopImage : require('@/assets/front-img/shop/store-placeholder.png')" alt/>
              </div>
              <div class="text-content">
                <h3>{{item.shopName ? item.shopName : item.companyName}}</h3>
                <div class="view-love">
                  <div>
                    <img src="@/assets/front-img/eye.png" style="height:16px" />
                    <span style="margin-left:10px">{{item.shopViewNum}}</span>
                  </div>
                  <div>
                    <img src="@/assets/front-img/like.png" style="height:16px" />
                    <span style="margin-left:10px">{{item.shopCollectNum}}</span>
                  </div>
                  <div>
                    <img src="@/assets/front-img/money.png" style="height:16px" />
                    <span style="margin-left:10px">{{item.shopDealNum}}</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="right">
              <el-button class="buy btn" @click="toShop(item.id)" type="primary">进店逛逛</el-button>
            </div>
          </div>
          <!-- <div class="item2-bottom">
            <ul>
              <li
                class="good"
                v-for="(good,index) in item.products"
                :key="index"
                @click="toShopDetail(item.id,good.id)"
              >
                <div class="img">
                  <img :src="good.image" alt />
                </div>
                <p>{{good.name}}</p>
              </li>
            </ul>
          </div>-->
        </div>
      </div>
      <Pagination :pageNo.sync="listQuery.pageNo" :pageSize.sync="listQuery.pageSize" :total="total"
        @change="getProduct()" />
    </div>

    <div class="footer">
      <Footer></Footer>
    </div>
  </div>
</template>

<script>
import {
  productPageByQo,
  pageVoByQo,
  getShopPageByQo,
} from "@/api/front-home.js";
import Footer from "@/views/front/components/Footer";
import Header from "@/views/front/components/Header";
import Pagination from "@/views/front/components/Pagination";
export default {
  data() {
    return {
      list: [],
      listQuery: {
        pageNo: 1,
        pageSize: 5,
        shopDealNum$sort: "",
        shopViewNum$sort: "",
        shopName$lk: "",
        shopCollectNum$sort: "",
      },

      total: 0,

      type: 0, //0(供应端)，1（销售端)
    };
  },
  async created() {
    this.listQuery.shopName$lk = this.$route.query.name$lk || "";

    // 设置默认的二级的分类

    this.getProduct();
  },

  components: {
    Footer,
    Header,
    Pagination,
  },
  computed: {
    defaultColor() {
      if (
        this.listQuery.shopViewNum$sort == "" &&
        this.listQuery.shopDealNum$sort == "" &&
        this.listQuery.shopCollectNum$sort == ""
      ) {
        return true;
      } else {
        return false;
      }
    },
  },
  inject: ['reload'],//引入
  watch: {
    $route(to, from) {
      this.listQuery.shopName$lk  = to.query.name$lk;
      this.getProduct();
    },
  },
  methods: {
    getProduct() {
      if (this.twoId) {
        this.listQuery.categoryId = this.twoId;
      } else {
        this.listQuery.categoryId = this.firstId;
      }
      getShopPageByQo(this.listQuery).then((res) => {
        this.list = res.list || [];
        this.total = res.totalCount;
      });
    },
    toShop(id) {
      // this.$router.push({ path: "/front-shop/home", query: { id: id } });

      //新建窗口打开
        const { href } = this.$router.resolve({ path: "/front-shop/home", query: { id: id } });
        window.open(href, '_blank');
    },
    // changeCollect() {
    //   if (this.listQuery.shopCollectNum$sort == "asc") {
    //     this.listQuery.shopCollectNum$sort = "desc";
    //   } else {
    //     this.listQuery.shopCollectNum$sort = "asc";
    //   }
    //   this.getProduct();
    // },
    // changeSale() {
    //   if (this.listQuery.shopDealNum$sort == "asc") {
    //     this.listQuery.shopDealNum$sort = "desc";
    //   } else {
    //     this.listQuery.shopDealNum$sort = "asc";
    //   }
    //   this.getProduct();
    // },
    // changeView() {
    //   if (this.listQuery.shopViewNum$sort == "asc") {
    //     this.listQuery.shopViewNum$sort = "desc";
    //   } else {
    //     this.listQuery.shopViewNum$sort = "asc";
    //   }
    //   this.getProduct();
    // },
    // changeDefault() {
    //   this.listQuery.shopDealNum$sort = "";
    //   this.listQuery.shopCollectNum$sort = "";
    //   this.listQuery.shopViewNum$sort = "";
    //   this.getProduct();
    // },
    changeSort(changeType, sort) {
      this.listQuery.shopCollectNum$sort = "";
      this.listQuery.shopDealNum$sort = "";
      this.listQuery.shopViewNum$sort = "";
      switch (changeType) {
        case 1:
          this.listQuery.shopDealNum$sort = sort && sort === "asc" ? "desc" : "asc";
          break;
        case 2:
          this.listQuery.shopViewNum$sort = sort && sort === "asc" ? "desc" : "asc";
          break;
        case 3:
          this.listQuery.shopCollectNum$sort = sort && sort === "asc" ? "desc" : "asc";
          break;

        default:
          break;
      }
      this.getProduct();
    },
  },
};
</script>
<style scoped>
[class^="el-icon-"],
[class*=" el-icon-"] {
  line-height: 0.5;
}
</style>
<style lang="scss" scoped>
.serve {
  .goods {
    width: 1200px;
    margin: 0 auto;
    .mianbao {
      height: 80px;
      line-height: 80px;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 300;
      color: #000000;
    }
    .sort {
      margin-top: 20px;

      background: #f6f6f6;
      .active {
        color: #965f29;
      }
      > ul {
        display: flex;
        align-items: center;
        li {
          display: flex;
          align-items: center;
          text-align: center;
          justify-content: center;
          width: 108px;
          height: 31px;
          line-height: 31px;
          border: 1px solid #e6e6e6;
          > span {
            i {
              display: block;
              &.active {
                color: #965f29;
              }
            }
          }
        }
      }
    }
    .productList {
      overflow: hidden;
      .item2-list {
        padding: 36px 0;
        border-bottom: 1px solid #ececec;
        .item2-top {
          display: flex;
          justify-content: space-between;
          align-items: center;
          .left {
            display: flex;
            .avator {
              margin-right: 24px;
              width: 66px;
              height: 66px;
              border-radius: 50%;
              overflow: hidden;
              > img {
                width: 100%;
                height: 100%;
              }
            }
            .text-content {
              h3 {
                margin: 0;
                font-size: 18px;
                font-family: Microsoft YaHei;
                font-weight: 400;
                color: #000000;
                margin-bottom: 25px;
              }
              .view-love {
                font-size: 15px;
                font-family: Microsoft YaHei;
                font-weight: 300;
                display: flex;
                color: #888888;
                > div {
                  margin-right: 20px;
                }
              }
            }
          }
          .right {
            .buy {
              width: 109px;
              height: 39px;
              background: #ffffff;
              border: 1px solid #965f29;
              border-radius: 3px;
              color: #965f29;
            }
          }
        }
        .item2-bottom {
          ul {
            display: flex;
            flex-wrap: wrap;

            .good {
              margin: 30px 15px;
              width: calc(16.6% - 30px);
              height: 158px;
              .img {
                width: 100%;
                height: 158px;
                > img {
                  width: 100%;
                  height: 100%;
                }
              }
              p {
                margin-top: 20px;
              }
            }
          }
        }
      }
    }
  }
}
</style>